package cn.lingyangwl.agile.auth.model.rqrs.client;

import cn.lingyangwl.agile.model.constants.ValidationCons;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;

/**
 * oauth客户端
 *
 * @author shenguangyang
 */
@Getter
@Setter
public class BaseOAuthClient {

	@ApiModelProperty(value = "客户端名称")
	@NotEmpty(message = ValidationCons.NOT_EMPTY)
	private String name;

	@ApiModelProperty(value = "资源列表")
	private String resourceIds;

	@ApiModelProperty(value = "客户端密钥")
	@NotEmpty(message = ValidationCons.NOT_EMPTY)
	private String clientSecret;

	@ApiModelProperty(value = "域")
	@NotEmpty(message = ValidationCons.NOT_EMPTY)
	private String scope;

	@ApiModelProperty(value = "认证类型")
	@NotEmpty(message = ValidationCons.NOT_EMPTY)
	private String authorizedGrantTypes;

	@ApiModelProperty(value = "扩展的认证类型")
	private String extGrantTypes;

	@ApiModelProperty(value = "重定向地址")
	private String webServerRedirectUri;

	@ApiModelProperty(value = "角色列表")
	private String authorities;

	@ApiModelProperty(value = "token 有效期")
	@NotNull(message = ValidationCons.NOT_EMPTY)
	@Min(value = 60 * 10, message = "令牌有效期至少需要10分钟")
	private Integer accessTokenValidity;

	@ApiModelProperty(value = "刷新令牌有效期")
	@NotNull(message = ValidationCons.NOT_EMPTY)
	@Min(value = 60 * 10, message = "刷新令牌有效期至少需要10分钟")
	private Integer refreshTokenValidity;

	@ApiModelProperty(value = "令牌扩展字段JSON")
	private String additionalInformation;

	@ApiModelProperty(value = "是否自动放行")
	@NotEmpty(message = ValidationCons.NOT_EMPTY)
	private String autoApprove;

	/**
	 * @see cn.hutool.core.util.BooleanUtil#toBooleanObject(String)
	 */
	@ApiModelProperty(value = "是否允许同时在线")
	@NotEmpty(message = ValidationCons.NOT_EMPTY)
	private String canSameTimeOnline;

	/**
	 * @see cn.hutool.core.util.BooleanUtil#toBooleanObject(String)
	 */
	@ApiModelProperty(value = "是否使用验证码")
	@NotEmpty(message = ValidationCons.NOT_EMPTY)
	private String useCaptcha;

	/**
	 * @see cn.lingyangwl.agile.model.constants.AppType
	 */
	@ApiModelProperty(value = "应用类型")
	@NotEmpty(message = ValidationCons.NOT_EMPTY)
	private String appType;

	/**
	 * 登录失败次数, 当登录失败达到一定次数之后, 就会被锁定 <br/>
	 * -1则不限制
	 */
	@ApiModelProperty(value = "登录失败次数")
	private Integer loginFailCount;

	@ApiModelProperty(value = "锁定间隔(单位为秒)")
	private Integer lockInterval;

	/**
	 * 连续被锁定时间乘子, 下一次锁定的时间 = 连续被锁定次数 * 锁定间隔 * 锁定时间乘子
	 */
	@ApiModelProperty(value = "连续被锁定时间乘子")
	private Integer lockMultiplier;

	@ApiModelProperty(value = "角色ids")
	private List<Long> roleIds = Collections.emptyList();

	private String remark;
}
